package com.example.leetcode.prcatice;

public class Test69 {

  public int mySqrt(int x) {

    int l = 0, r = x, ans = -1;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if ((long) mid * mid <= x) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    return ans;
  }
}

class Demo69 {
  public static void main(String[] args) {
    int x = 8;
    Test69 t = new Test69();
    System.out.println(t.mySqrt(x));
  }
}
